$(function () {
    $("#jqGrid").jqGrid({
        url: '../merchantinfo/list',
        datatype: "json",
        colModel: [			
			{ label: '申请人', name: 'username', index: 'username', width: 50 }, 			
			{ label: '公司/企业/商铺', name: 'shopName', index: 'shopname', width: 80 }, 			
			{ label: '商户号', name: 'merchantNo', index: 'merchant_no', width: 100 }, 			
			{ label: '联系电话', name: 'mobilephone', index: 'mobilephone', width: 60 }
			/*{ label: '银行名称', name: 'bankName', index: 'bank_name', width: 100 }, 
			{ label: '银行开户名', name: 'bankUser', index: 'apply_time', width: 50 }, 
			{ label: '银行卡号', name: 'bankCard', index: 'bank_name', width: 120 }*/
        ],
		viewrecords: true,
        height: "100%",
        rowNum: 10,
		rowList : [10,20,30],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

function showInfo(id){
	parent.layer.open({
		  type: 2,
		  title: '二维码列表',
		  shadeClose: true,
		  shade: 0.8,
		  fixed: false, //不固定
		  maxmin: true,
		  area: ['60%', '80%'],
		  //content: 'merchant/listQRCode.html?id='+id //iframe的url
		  content: 'merchantinfo/getCodeList.do?id='+id //iframe的url
		}); 
}

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			shopName: ""
		},
		showList: true,
		title: null,
		merchantInfo: {},
		selected: '',
		cooperationoptions: [
	      { text: '收款', value: '1' },
	      { text: '吸粉', value: '2' }
	    ],
	    statusoptions:[
	    	{text:"申请",value:"0"},
	    	{text:"正常",value:"1"},
	    	{text:"冻结",value:"2"},
	    	{text:"挂失",value:"3"}
	    ],
	    iscreditCardoptions:[{text:"否",value:"0"},
	    	{text:"是",value:"1"}],
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.merchantInfo = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.merchantInfo.id == null ? "../merchantinfo/save" : "../merchantinfo/update";
			$.ajax({
				type: "POST",
			    url: url,
			    data: JSON.stringify(vm.merchantInfo),
			    success: function(r){
			    	if(r.code == 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		getInfo: function(id){
			$.get("../merchantinfo/info/"+id, function(r){
                vm.merchantInfo = r.merchantInfo;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			page = 1;
			var keyword = $("#keyword").val();
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page,
                postData:{keyword:keyword},
                
            }).trigger("reloadGrid");
		},
		editBankInfo: function(event){
			var id = getSelectedRow();
			var rowData = $('#jqGrid').jqGrid('getRowData',id);
			var merchantNo = rowData.merchantNo;
			
			if(id == null){
				return ;
			}
			if(merchantNo == null || merchantNo == ''){
				alert('商户号不能为空');
				return ;
			}
			parent.layer.open({
				  type: 2,
				  title: '银行信息维护',
				  shadeClose: true,
				  shade: 0.8,
				  fixed: false, //不固定
				  maxmin: true,
				  area: ['80%', '80%'],
				  content: 'bankInfo/bankInfoList.html?merchantNo='+merchantNo //iframe的url
				});
		},
		editPayCh: function(event){
			var id = getSelectedRow();
			//var id =$('#jqGrid').jqGrid('getGridParam','selrow');
			var rowData = $('#jqGrid').jqGrid('getRowData',id);
			var merchantNo = rowData.merchantNo;
			if(id == null){
				return ;
			}
			if(merchantNo == null || merchantNo == ''){
				alert('商户号不能为空');
				return ;
			}
			parent.layer.open({
				  type: 2,
				  title: '支付渠道信息',
				  shadeClose: true,
				  shade: 0.8,
				  fixed: false, //不固定
				  maxmin: true,
				  area: ['80%', '80%'],
				  content: 'payChannel/payList.html?merchantNo='+merchantNo //iframe的url
				});
		}
	}
});